<!-- 分享海报  -->
<template>
	<view>
		<!-- #ifndef APP-PLUS -->
		<view class="mask flex-box flex-center align-center" v-if='ShareQrCode' @click="ShareQrTab(false)">
			<view class="shareboxs" @click.stop>
				<view>
					<image show-menu-by-longpress class="qrImg" mode="aspectFit" :src="ShareQrCode" @click="previewImg"></image>
				</view>
				<view class="shareImgTxt">长按保存或直接分享</view>
				<text class="iconfont icon-guanbi size40" @click="ShareQrTab(false)"></text>
			</view>
		</view>
		<!-- #endif -->
		
		<!-- #ifdef APP-PLUS -->
		<view class="mask" @click="ShareQrTab(false)">
			<shareUI style="z-index: 999;" :shareType='shareType' :shareId='shareId' v-if='showShare' @show='showShare = false'></shareUI>
		</view>
		<!-- #endif -->
	</view>
</template>

<script>
	import shareUI from './shareUI.vue'
	var that
	export default {
		/**
		 * pageType:扫码进来在启动页判断页面类型
		 * ***/
		props: ['myid', 'type', 'path', 'pageType'],
		components: {
			shareUI
		},
		data() {
			return {
				shareType: this.type, //1首页海报图 2商品海报图 3活动海报图 4团购邀请海报 5分销邀请海报 6商品视频海报 7课程目录海报 8表单海报图 9门店
				shareId: this.myid, //商品ID/活动ID/参团ID
				imgUrl: this.imgUrl,
				ShareQrCode: '',
				bid: uni.getStorageSync('bid'),
				showShare: true,
			}
		},
		created() {
			that = this;
			that.showShare = true
			// #ifndef APP-PLUS
			uni.showLoading({
				title: '海报合成中~'
			})
			// #endif
			that.$http.get({ // 获取海报
				url: '/singleSaleApi/getShareImg',
				data: {
					id: that.shareId, //商品ID/活动ID/参团ID
					bid: that.bid,
					v_id: uni.getStorageSync("vid"),
					type: that.shareType, //获取点
					group: that.shareType == 4 ? 1 : '',
					path: '/#/pages/index/index?p=' + that.pageType, //页面类型和页面参数
				}
			}).then(res => {
				if (res.data) {
					that.ShareQrCode = res.data;
				} else {
					this.$emit("closePoster")
					uni.showToast({
						icon: 'none',
						title: res.msg
					})
				}
				uni.hideLoading()
			})
		},
		methods: {
			ShareQrTab() {
				this.$emit("closePoster")
			},
			previewImg() {
				uni.previewImage({
					urls: [this.ShareQrCode]
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.shareboxs {
		.qrImg {
			width: 650rpx;
			height: 70vh;
			text-align: center;
			position: relative;
		}
		.shareImgTxt{
			color: white;
			font-size: 28upx;
			text-align: center;
			margin-top: 20upx;
		}
	}
</style>
